package com.rabbitMq.producer;

import com.rabbitMq.RabbitApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = RabbitApplication.class)
public class TestRabbitMq {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    //这是使用Direct(直接模式)来发送消息
    @Test
    public void test01(){
        rabbitTemplate.convertAndSend("zelin","我是大王");
    }

    //使用Fanout（分列模式）来发送消息
    @Test
    public void test02(){
        rabbitTemplate.convertAndSend("zelin_school","","使用Fanout发送“我是大王”");
    }
    //使用topic（主题模式）来发送消息 RoutingKey: goods.log
    @Test
    public void test03(){
        rabbitTemplate.convertAndSend("fourbooks","goods.log","使用goods.log发送消息");
    }
    //使用topic（主题模式）来发送消息 RoutingKey: goods.#
    @Test
    public void test04(){
        rabbitTemplate.convertAndSend("fourbooks","goods.aa","使用goods.aa发送消息");
    }
    //使用topic（主题模式）来发送消息 RoutingKey: #.log
    @Test
    public void test05(){
        rabbitTemplate.convertAndSend("fourbooks","aa.log","使用aa.log发送消息");
    }
}
